package com.ihelp.controller;

import com.ihelp.entities.CommonResult;
import com.ihelp.pojo.HospitalDepartment;
import com.ihelp.service.HospitalDepartmentService;
import com.ihelp.service.HospitalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LiuZiMing
 * @since 2023-05-23
 */
@RestController
@Slf4j
@RequestMapping("/hospitalDepartment")
public class HospitalDepartmentController {
    @Autowired
    private HospitalDepartmentService hospitalDepartmentService;

    @GetMapping("/all")
    public CommonResult getAllHospitalDepartment() {
        List<HospitalDepartment> allHospitalDepartment = hospitalDepartmentService.getAllHospitalDepartment();
        return new CommonResult(200, "获取所有医院部门成功", allHospitalDepartment);
    }

    @GetMapping("/id/{id}")
    public CommonResult getHospitalDepartmentById(@PathVariable Integer id){
        HospitalDepartment hospitalDepartment = hospitalDepartmentService.getHospitalDepartment(id);
        if(hospitalDepartment!=null){
            return new CommonResult<>(200,"根据id:"+id+",获取医院部门成功",hospitalDepartment);
        }else {
            return new CommonResult<>(204,"根据id:"+id+",未找到医院部门");
        }
    }


}
